﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<TimeTableManagement.Entities.Tb_Education>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxClasses" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
    <% using (Html.BeginForm()) { %>
    <dx:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Width="100%"
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css" TabSpacing="3px">
        <TabPages>
            <dx:TabPage Text="Thông tin cơ bản">
                <ContentCollection>
                    <dx:ContentControl runat="server" SupportsDisabledAttribute="True">
                      <%--Noi dung tab 1--%>  
                        
    <%: Html.ValidationSummary(true) %>
   
        <%: Html.HiddenFor(model => model.id) %>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.code) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.code) %>
            <%: Html.ValidationMessageFor(model => model.code) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.name) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.name) %>
            <%: Html.ValidationMessageFor(model => model.name) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.maxcredit) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.maxcredit) %>
            <%: Html.ValidationMessageFor(model => model.maxcredit) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.countterm)%>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.countterm)%>
            <%: Html.ValidationMessageFor(model => model.countterm)%>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.department) %>
        </div>
        <div class="editor-field">
            <%: Html.DropDownList("department", String.Empty) %>
            <%: Html.ValidationMessageFor(model => model.department) %>
        </div>
        <div class="editor-label">
            Term Start
        </div>
        <div class="editor-field">
            <%: Html.DropDownList("termstart", String.Empty) %>
        </div>
        <div class="editor-label">
            <%: Html.LabelFor(model => model.description) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.description) %>
            <%: Html.ValidationMessageFor(model => model.description) %>
        </div>
        
                    </dx:ContentControl>
                </ContentCollection>
            </dx:TabPage>
            <dx:TabPage Text="Danh sách môn học">
                <ContentCollection>
                    <dx:ContentControl runat="server" SupportsDisabledAttribute="True">
                       <%-- Noi dung tab 2--%>
     <%--                  <div class="display-label">List Course</div>--%>
    <div class="display-field">
        <div id="viewtablediv">
                        <%--NOi dung cho table--%>
                        <table style="width:100%" id="Table1" class="example table-autosort
                            table-autofilter table-autopage:20 
                            table-stripeclass:alternate 
                            table-page-number:t1page table-page-count:t1pages 
                            table-filtered-rowcount:t1filtercount 
                            table-rowcount:t1allcount">
                        <thead>
                        <tr>
                            <th class="table-sortable:alphanumeric">
                                Course
                            </th>
                            <th class="table-sortable:alphanumeric">
                                Name
                            </th>
                            <th class="table-sortable:alphanumeric table-filterable">
                                Term
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <%
                        foreach (TimeTableManagement.Entities.EduList item in ViewBag.listcourse)
                        { %>

                            <td><%: item.code %></td>
                            <td><%: item.name %></td>
                            <td><%: item.term %></td>
                        </tr>
                            <% } %>
                            </tbody>
                            <tfoot>
	                        <tr>
		                        <td class="table-page:previous" style="cursor:pointer; text-align:right"><img src="../../Content/iconprevious.png" /></td>
		                        <td></td>
                                <td class="table-page:next" style="cursor:pointer; text-align:left"> <img src="../../Content/iconnext.png" /></td>
	                        </tr>
                        </tfoot>
                        </table>
                    </div>
                    <a href="#" onclick="jQuery('#dialog').dialog('open'); return false">Chọn môn học cho chương trình học</a>
        
    </div>
    <div id="dialog" title="Chosen Course for Education">
<table id="t1" class="example table-autosort
 table-autofilter table-autopage:8 
 table-stripeclass:alternate 
 table-page-number:t1page table-page-count:t1pages 
 table-filtered-rowcount:t1filtercount 
 table-rowcount:t1allcount">
 <thead>
    <tr>
        <th>
            <input type="button" onclick="return updatedata()" value="Xong" />        
        </th>
        <th class="table-sortable:alphanumeric">
            Môn học
        </th>
        <th class="table-sortable:alphanumeric table-filterable">
            Khoa
        </th>
        <th>
            Học kỳ
        </th>
    </tr>
 </thead>   
 <tbody>
    <% TimeTableManagement.QLSVContext _context = new TimeTableManagement.QLSVContext();
       var M = _context.Tb_Course.ToList();
       foreach (var item in M)
       { %>
       <tr>
    <% bool havecourse=false;
       int term = 0;
        foreach (TimeTableManagement.Entities.EduList item_edu in ViewBag.listcourse)
       { 
           if(item_edu.code.Contains(item.name) 
               || item.name.Contains(item_edu.code)
               || item_edu.code.Contains(item.code) 
               || item.code.Contains(item_edu.code))
           {
               havecourse = true;
               term = item_edu.term;
               break;
           }
       } 
        %>
        <% if (havecourse)
           { %>
            <td>
                 <%--<input class="checkbox" id="Checkbox<%: item.id %>" type="checkbox" checked="checked" /> --%>
                 <input id="<%: item.id %>" code="<%: item.code %>" credit="<%: item.credit %>" namecode="<%: item.name %>" 
                    class="checkboxitem" type="checkbox" checked="checked"/>
            </td>
            <td id="Td1">
                <%: Html.DisplayFor(modelItem => item.code)%> - <%: Html.DisplayFor(modelItem => item.name)%>
            </td>
            <td id="Td2">
                <%: Html.DisplayFor(modelItem => item.Tb_Department.name)%>
            </td>
            <td>
                <%--<input style="width:30px" id="HK<%: item.id%>" type="text" value="<%: term %>"/>--%>
                <input style="width:30px" id="Textbox<%: item.id %>" type="text" value="<%: term %>"/>

            </td>
            <% }
           else
           {%> 
            <td>
                <%-- <input class="checkbox" id="Checkbox<%: item.id %>" type="checkbox" /> --%>
                 <input id="<%: item.id %>"" code="<%: item.code %>" credit="<%: item.credit %>" namecode="<%: item.name %>" 
                    class="checkboxitem" type="checkbox" />
            </td>
            <td id="Td3">
                 <%: Html.DisplayFor(modelItem => item.code)%> - <%: Html.DisplayFor(modelItem => item.name)%>
            </td>
            <td id="Td2">
                <%: Html.DisplayFor(modelItem => item.Tb_Department.name)%>
            </td>
            <td>
               <%-- <input style="width:30px" id="HK<%: item.id%>" type="text" value=""/>--%>
                <input style="width:30px" id="Textbox<%: item.id %>" type="text"/>
            </td>
                <% } %>
       
    </tr>
    <% } %>
</tbody>   
<tfoot>
	<tr>
		<td class="table-page:previous" style="cursor:pointer; text-align:right"><img src="../../Content/iconprevious.png" /></td>
		<td style="text-align:center" colspan="2" class="table-page-number:t1page">Page <span id="t1page"></span>&nbsp;of&nbsp;<span id="t1pages"></span></td>
        <td class="table-page:next" style="cursor:pointer; text-align:left"> <img src="../../Content/iconnext.png" /></td>
	</tr>
</tfoot>     
    </table> 
    
    
</div>
                    </dx:ContentControl>
                </ContentCollection>
            </dx:TabPage>
        </TabPages>
        <LoadingPanelImage Url="~/App_Themes/Aqua/Web/Loading.gif">
        </LoadingPanelImage>
        <Paddings Padding="2px" PaddingLeft="5px" PaddingRight="5px" />
        <ContentStyle>
            <Border BorderColor="#AECAF0" BorderStyle="Solid" BorderWidth="1px" />
        </ContentStyle>
    </dx:ASPxPageControl>
    <input id="listcourse" name="listcourse" type="hidden" value="<%: Model.listcourse %>"/>
    <%--Can mot javascript: khi co su thay doi trong table listcource thi noi dung cua hidden listcourse cung thay doi theo.--%>
    <p>
            <input type="submit" value="Save" onclick='return updatelistcourse()'/>
        </p>

<% } %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
    $(function () {
        $("#dialog").dialog({
            bgiframe: true,
            height: 450,
            width: 700,
            modal: true,
            autoOpen: false,
            resizable: false
        })
    });
</script>
<script type="text/javascript">
    function updatedata() {
        //cap nhat json
        if (updateJsonString()) {
            //dong cua so
            $.ajax({
                type: "POST",
                url: "/education/list?listedu=" + document.getElementById('listcourse').value,
                success: function (data) {
                    document.getElementById('viewtablediv').innerHTML = data;
                }
            });
            document.getElementsByClassName('ui-dialog-titlebar-close').item(0).click();
            return false;
        }
        return false;
    }
    </script>
    <script>
        function updateJsonString() {
            $json = "";
            $count = 0;
            $inputs = document.getElementsByClassName('checkboxitem');
            for ($i = 0; $i < $inputs.length; $i++) {
                input = $inputs.item($i);
                if (input.checked == true) {
                    $id = input.id;
                    $code = input.getAttribute('code');
                    $credit = input.getAttribute('credit');
                    $count = $count + parseInt($credit);
                    $namecode = input.getAttribute('namecode').trim();
                    $term = document.getElementById("Textbox" + $id).value;
                    if ($term == "") {
                        alert("Vui lòng kiểm tra kỹ lại thông tin");
                        return false;
                    }
                    $json = $json + ',{ "term": ' + $term + ', "idcourse": ' + $id + ', "code": "' + $code + '", "name": "' + $namecode + '"}';
                }
            }
            if ($json == "") {
                document.getElementById('listcourse').value = "";
                document.getElementById('maxcredit').value = "0";
                return true;
            } else {
                $json = $json.substr(1);
                $json = '[' + $json + ']';
                document.getElementById('listcourse').value = $json;
                document.getElementById('maxcredit').value = $count;
                return true;
            }
        }
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
